/**
 * 
 */
package com.cp16.tss.handler;

import java.awt.Color;

import com.cp16.tss.bo.UserLoginBO;
import com.cp16.tss.common.CommonMessage;
import com.cp16.tss.dto.UserLogin;
import com.cp16.tss.form.CustomerForm;
import com.cp16.tss.form.UserLoginForm;
import com.cp16.tss.validation.UserLoginFormValidation;

/**
 * @author ADMIN
 * 
 */
public class UserLogInHandler {

	private UserLoginBO userLoginBO = new UserLoginBO();


	// Method sign in
	@SuppressWarnings("deprecation")
	public boolean signInLogInForm(UserLoginForm userLoginForm) {
		boolean flag = false;
		if (UserLoginFormValidation.validateLoginForm(userLoginForm)) {
			UserLogin userLogin = userLoginBO.getUserByName(userLoginForm.getTxtUserName().getText());
			if (userLogin != null) {
				if (userLogin.getPassword().equals(
						userLoginForm.getPwPassword().getText())) {
					CustomerForm customerForm = new CustomerForm();
					customerForm.setVisible(true);
					userLoginForm.setVisible(false);
					flag = true;
				} else {
					userLoginForm.getLblCheckForm().setText(CommonMessage.PASSWORD_MISS);
					userLoginForm.getLblCheckForm().setForeground(Color.WHITE);
				}
			} else {
				userLoginForm.getLblCheckForm().setText(CommonMessage.USER_NOT_EXISTED);
				userLoginForm.getLblCheckForm().setForeground(Color.WHITE);
			}
		}
		return flag;
	}

}
